package view.action;

import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import model.pojo.UserInfo;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;

public class Login {
	Logger logger = Logger.getLogger(Login.class);
	public String userName;
	public String password;

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String execute() {
		return "SUCCESS";
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public String login() {
		UserInfo user = new UserInfo();
		user.setUserName(userName);
		user.setPassword(password);
		Map session = ActionContext.getContext().getSession();
		session.put("userLogin", user);
		HttpServletResponse response = ServletActionContext.getResponse();
		try {
			response.sendRedirect("index.action");
		} catch (IOException e) {
			e.printStackTrace();
			logger.error(e.getMessage());
		}
		return "SUCCESS";
	}
}
